var Merchants = Vue.component('merchants', function (resolve, reject) {
    axios.get('views/merchants/merchants.html?timestamp=' + timestamp).then(function (res) {
        resolve({
            template: res.data,
            data(){
                return {
                    needAdminRole:CommonUtils.checkRole('admin')||CommonUtils.checkRole("access"),
                    tableData: [],
                    disableDetailForm:false,
                    dialogFormVisible: false,
                    form: {},
                    pageInfo:{
                        currentPage:1,
                        pageSize:10,
                        // srch_EQ_delete:false,
                        srch_LIKE_pidName:'',
                        totalNum:10,
                    },
                    editForm:{},
                    showEditWin:false,
                    formLabelWidth: '150px',
                    
                }
            },
            methods:{

                handleCurrentChange: function(currentPage){
                    this.pageInfo.currentPage = currentPage;
                    this.initData();
                },
                initData:function(){
                    var url = APIs.merchants.list+"/"+this.pageInfo.currentPage;
                    httpInvoker.get(url,{
                        params:this.pageInfo,
                        paramsSerializer: params => {
                            return Qs.stringify(params, { indices: false })
                        }
                    }).then(res=>{
                        if (res.data.status == '00') {
                            this.tableData = res.data.data.content;
                            this.pageInfo.totalPage = res.data.data.totalElements; 
                        }else {
                            this.$alert(res.data.msg, '', {
                                confirmButtonText: '确定'
                            });
                        }
                        
                    }).catch(()=>{

                    });
                },
                save:function(){
                    var url = APIs.merchants.save;
                    httpInvoker.post(url,this.form).then(res=>{
                        if ( res.data.status == '00') {
                            this.$alert(res.data.data, '', {
                                confirmButtonText: '确定'
                            });
                            this.initData();
                        }else {
                            this.$alert(res.data.msg, '', {
                                confirmButtonText: '确定'
                            });
                        }
                        
                    }).catch(()=>{

                    });
                },
                onSubmit:function(){
                    this.$set(this.pageInfo,'currentPage',1);
                    this.initData();
                },edit:function(){
                    var url = APIs.merchants.update+"/"+this.editForm.id;
                    httpInvoker.post(url,this.editForm).then(res=>{
                        if ( res.data.status == '00') {
                            this.$alert(res.data.data, '', {
                                confirmButtonText: '确定'
                            });
                            this.initData();
                        }else {
                            this.$alert(res.data.msg, '', {
                                confirmButtonText: '确定'
                            });
                        }
                        
                    }).catch(()=>{

                    });
                },deletePid:function(row){

                    this.$confirm('停用'+row.pidName+'，会停用'+row.pidName+'下面的所有的生活号，商品及作废订单,订单作废后无法恢复！确定要停用吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        var url = APIs.merchants.delete+"/"+row.id;
                    
                        httpInvoker.post(url,{}).then(res=>{
                             if ( res.data.status == '00') {
                                 this.$alert("停用成功!", '', {
                                     confirmButtonText: '确定'
                                 });
                                 this.initData();
                             }else {
                                 this.$alert(res.data.msg, '', {
                                     confirmButtonText: '确定'
                                 });
                             }
                             
                         }).catch(()=>{
     
                         });
                    }).catch(() => {

                    });
                  
                },startPid:function(id){
                    var url = APIs.merchants.start+"/"+id;
                    
                    httpInvoker.post(url,{}).then(res=>{
                         if ( res.data.status == '00') {
                             this.$alert("启用成功!", '', {
                                 confirmButtonText: '确定'
                             });
                             this.initData();
                         }else {
                             this.$alert(res.data.msg, '', {
                                 confirmButtonText: '确定'
                             });
                         }
                         
                     }).catch(()=>{
 
                     });
                }
               
            },
            mounted: function () {
                this.initData();
            },
        })
    })
})